Ext.define('appfe.stockor.statist.buyinpoint.BuyinPoint', {
	extend: 'Ext.grid.Panel',
	xtype: 'statist-buyinpoint',
	requires: ['Ext.toolbar.Paging',
		'appfe.stockor.statist.buyinpoint.BuyinPointController',
		'appfe.stockor.statist.buyinpoint.BuyinPointModel',
		'appfe.stockor.statist.buyinpoint.form.BuyinPointLogWindow',
		'appfe.stockor.statist.buyinpoint.form.BuyinPointLogGrid',
		'appfe.stockor.statist.buyinpoint.form.RealtimeBuyinPointForm',
		'appfe.stockor.statist.chart.KLine'],
	controller: 'stockor.statist.buyinpoint.BuyinPoint',
	viewModel: { type: 'stockor.statist.buyinpoint.BuyinPoint' },
	viewConfig: {
		//markDirty: false //修改不出现红色三角标, 最新用record.commit()
		trackOver: true, // 鼠标滑过当前行时, 反显
		stripeRows: true, // 行颜色白灰条纹间隔显示
		enableTextSelection: true, // 允许选择文本
		emptyText: '点击查询按钮',
		deferEmptyText: false
	},
	//iconCls: 'x-fa fa-lightbulb-o',
	//animCollapse: false,
	//collapsible: true,
	columnLines: true, // 表格分隔线
	border: false,
	autoLoad: false,
	height: '100%',
	// frame: true,
	disableSelection: false,
	scrollable: true,
	loadMask: true, // 显示数据加载中蒙层
	selModel: {
		type: 'checkboxmodel', //带选择框
		injectCheckbox: 0, //checkbox位于哪一列，默认值为0
		mode: 'SIMPLE', //支持三种模式 'SINGLE' / 'SIMPLE' / 'MULTI'支持ctrl,shift的操作 
		allowDeselect: true, //mode: 'SINGLE'下才有效
		checkOnly: false //只能点击checkbox才能选中
	},
	bind: {
		store: '{buyinPointStore}'
		//title: '参数配置: {appName}' //
	},
	columns: {
		defaults: {
			sortable: true,
			menuDisabled: true,
			//flex: 2
			defaults: {
				sortable: true,
				menuDisabled: true
			}
		},
		items: [
			{ xtype: 'rownumberer', resizable: true }, //显示行数
			{ text: 'ID', width: 70, dataIndex: 'id', renderer: 'viewCellIdRender' },
			{ text: '代码', width: 90, dataIndex: 'slimsymbol', renderer: 'viewCellSymbolRender' },
			{ text: '名称', minWidth: 70, maxWidth: 550, dataIndex: 'name' },
			{ text: '级别', width: 70, dataIndex: 'grade' },
			{ text: '状态', width: 70, dataIndex: 'status', renderer: 'viewCellStatusRender' },
			{
				text: '日志最新点',
				columns: [
					{ xtype: 'datecolumn', text: '时间', width: 100, dataIndex: 'logInfoTime', format: 'Y-m-d' },
					{ xtype: 'numbercolumn', text: '收价', width: 85, dataIndex: 'logTclosePrice', align: 'right', format: '￥0.00', renderer: 'viewCellLogTclosePriceRender' }
				]
			},
			{
				text: '背驰分析点',
				columns: [
					{ xtype: 'datecolumn', text: '时间', width: 100, dataIndex: 'infoTime', format: 'Y-m-d' },
					{ xtype: 'numbercolumn', text: '收价', width: 85, dataIndex: 'tclosePrice', align: 'right', format: '￥0.00', renderer: 'viewCellTclosePriceRender' }
				]
			},
			{
				text: '最低点',
				columns: [
					{ xtype: 'datecolumn', text: '时间', width: 100, dataIndex: 'lowestInfoTime', format: 'Y-m-d' },
					{ xtype: 'numbercolumn', text: '最低', width: 85, dataIndex: 'lowestTlowPrice', align: 'right', format: '￥0.00', renderer: 'viewCellLowestTlowPriceRender' }
				]
			},
			// {
			// 	text: '当前四价',
			// 	columns: [
			// 		{ xtype: 'datecolumn', text: '时', width: 100, dataIndex: 'logInfoTime', format: 'Y-m-d' },
			// 		{ xtype: 'numbercolumn', text: '开', width: 80, dataIndex: 'logTopenPrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '收', width: 80, dataIndex: 'logTclosePrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '高', width: 80, dataIndex: 'logThighPrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '低', width: 80, dataIndex: 'logTlowPrice', align: 'right', format: '￥0.00' },
			// 	]
			// },
			// {
			// 	text: '背驰四价',
			// 	columns: [
			// 		{ xtype: 'datecolumn', text: '时', width: 100, dataIndex: 'infoTime', format: 'Y-m-d' },
			// 		{ xtype: 'numbercolumn', text: '开', width: 80, dataIndex: 'topenPrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '收', width: 80, dataIndex: 'tclosePrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '高', width: 80, dataIndex: 'thighPrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '低', width: 80, dataIndex: 'tlowPrice', align: 'right', format: '￥0.00' },
			// 	]
			// },
			// {
			// 	text: '低点四价',
			// 	columns: [
			// 		{ xtype: 'datecolumn', text: '时', width: 100, dataIndex: 'lowestInfoTime', format: 'Y-m-d' },
			// 		{ xtype: 'numbercolumn', text: '开', width: 80, dataIndex: 'lowestTopenPrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '收', width: 80, dataIndex: 'lowestTclosePrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '高', width: 80, dataIndex: 'lowestThighPrice', align: 'right', format: '￥0.00' },
			// 		{ xtype: 'numbercolumn', text: '低', width: 80, dataIndex: 'lowestTlowPrice', align: 'right', format: '￥0.00' },
			// 	]
			// },
			{ text: '偏移', width: 70, dataIndex: 'offsetDays' },
			{
				text: '利润',
				columns: [
					{ xtype: 'numbercolumn', text: '额', width: 75, dataIndex: 'tcloseIncreaseAmount', align: 'right', renderer: 'viewCellProfitAmountRender' }, //format: '￥0.00',
					{ xtype: 'numbercolumn', text: '率', width: 70, dataIndex: 'tcloseProfitRatio', align: 'right', renderer: 'viewCellProfitRatioRender' } //format: '0.0000%', renderer: function (rate) { return Ext.util.Format.number(rate * 100, '0.00%'); }
				]
			},
			{
				text: '当前各均线MA相对位置比较',
				columns: [
					{ text: '收≥5', width: 75, dataIndex: 'closeOverMa5', renderer: 'viewCellBooleanRender' },
					{ text: '5≥10', width: 75, dataIndex: 'ma5OverMa10', renderer: 'viewCellBooleanRender' },
					{ text: '5≥13', width: 75, dataIndex: 'ma5OverMa13', renderer: 'viewCellBooleanRender' }
				]
			},
			//{ xtype: 'numbercolumn', text: 'MACD<br>斜率', width: 75, dataIndex: 'macdSlope', format: '0.00' },
			{
				text: '背驰点前溯周期最低价状态',
				columns: [
					{ text: '33', width: 55, dataIndex: 'backoff34TermsIslowest', renderer: 'viewCellBooleanRender' },
					{ text: '55', width: 55, dataIndex: 'backoff55TermsIslowest', renderer: 'viewCellBooleanRender' },
					{ text: '89', width: 55, dataIndex: 'backoff89TermsIslowest', renderer: 'viewCellBooleanRender' },
					{ text: '144', width: 55, dataIndex: 'backoff144TermsIslowest', renderer: 'viewCellBooleanRender' }
				]
			},
			{ text: '实时状态', width: 95, dataIndex: 'realtimeStatus', renderer: 'viewCellRealtimeStatusRender' },
			{
				text: '现价信息',
				columns: [
					{ xtype: 'numbercolumn', text: '现价', width: 75, dataIndex: 'currentPrice', align: 'right', format: '￥0.00', renderer: 'viewCellCurrentPriceRender' },
					{ xtype: 'datecolumn', text: '时间', width: 155, dataIndex: 'currentTime', format: 'Y-m-d H:i:s' },
					{ text: '额', width: 80, dataIndex: 'realtimetCloseIncreaseAmount', align: 'right', renderer: 'viewCellProfitAmountRender' }, //format: '￥0.00',
					{ text: '率', width: 75, dataIndex: 'realtimetCloseProfitRatio', align: 'right', renderer: 'viewCellProfitRatioRender' } //format: '0.0000%', renderer: function (rate) { return Ext.util.Format.number(rate * 100, '0.00%'); }
				]
			},
			//{ xtype: 'datecolumn', text: '创建时间', width: 160, dataIndex: 'createDate',  format: 'Y-m-d H:i' },
			//{ xtype: 'datecolumn', text: '修改时间', width: 160, dataIndex: 'modifyDate',  format: 'Y-m-d H:i:s' },
			{ text: '备注', flex: 1, dataIndex: 'comments', sortable: false, producesHTML: false, renderer: 'viewCellPlainTextRender' }
		]
	},
	dockedItems: [
		{/* 顶部查询栏 */
			xtype: 'panel',
			reference: 'top',
			dock: 'top',
			padding: '16 10 16 10',
			frame: true,
			scrollable: true,
			layout: 'vbox',
			defaults: {
				xtype: 'container',
				layout: 'hbox',
				scrollable: true,
				width: '100%',
                border: true
			},
			items: [
				{ // 第一行 container
					defaults: { margin: '0 5 0 5' },
					items: [
						{
							xtype: 'combo',
							name: 'queryKey',
							reference: 'queryKey',
							editable: false,
							bind: {
								store: '{queryKeyStore}'
							},
							listConfig: { itemTpl: ['<div data-qtip="值:{code},类型:{type}">{text}</div>'] },
							//multiSelect: true,
							queryMode: 'local',
							valueField: 'code',
							displayField: 'text',
							value: 'slimsymbol',
							allowBlank: false,
							width: 80
						}, {
							xtype: 'textfield',
							fieldLabel: ':',
							labelWidth: 60,
							labelAlign: 'right',
							anchor: '100%',
							//width: 160,
							reference: 'queryValue',
							itemId: 'queryValue',
							emptyText: '多个值由逗号分隔'
						}, {
							xtype: 'combo',
							name: 'queryInfoTimeKey',
							reference: 'queryInfoTimeKey',
							editable: false,
							bind: {
								store: '{queryInfoTimeTypeStore}'
							},
							listConfig: { itemTpl: ['<div data-qtip="值:{code},类型:{type}">{text}</div>'] },
							//multiSelect: true,
							queryMode: 'local',
							valueField: 'code',
							displayField: 'text',
							value: 'logTime',
							allowBlank: false,
							width: 95
						}, {
							xtype: 'datetimefield',
							//fieldLabel: '时间点',
							//labelAlign: 'right',
							//labelWidth: 60,
							anchor: '100%',
							//width: 250,
							width: 180,
							reference: 'startDate',
							itemId: 'startDate',
							format: 'Y-m-d H:i:s',
							initFormat: "Y-m-d 00:00:00",
							editable: false,
							//vtype: 'daterange',//TODO: datetimefield对vtype daterange响应有问题, 暂时不用, 后续解决
							endDateField: 'endDate' // id of the end date field
						}, {
							xtype: 'datetimefield',
							fieldLabel: '~',
							labelWidth: 15,
							//labelAlign: 'right',
							anchor: '100%',
							width: 205,
							labelSeparator: '', //分隔符
							reference: 'endDate',
							itemId: 'endDate',
							format: 'Y-m-d H:i:s',
							initFormat: "Y-m-d 23:59:59",
							editable: false,
							//vtype: 'daterange',//TODO: datetimefield对vtype daterange响应有问题, 暂时不用, 后续解决
							startDateField: 'startDate' // id of the start date field
						}, {
							xtype: 'combo',
							fieldLabel: '状态',
							labelAlign: 'right',
							labelWidth: 30,
							reference: 'status',
							editable: false,
							bind: {
								store: '{buyinPointStatusStore}'
							},
							multiSelect: true,
							queryMode: 'local',
							valueField: 'code',
							displayField: 'text',
							value: ['NEW', 'OPEN'],
							triggerAction: 'all',
							width: 180
						}, {
							xtype: 'checkboxgroup',
							itemId: 'grade',
							fieldLabel: '级别',
							labelAlign: 'right',
							reference: 'grade',
							anchor: '100%',
							labelWidth: 60,
							columns: [60, 60],
							items: [
								{ boxLabel: 'DAY', name: 'DAY', checked: 'true' },
								{ boxLabel: 'M30', name: 'M30' }
							]
						}, { //查询按钮
							xtype: 'button',
							text: '查询',
							iconCls: 'x-fa fa-search',
							handler: 'searchFn'
						}
					]
				}
			]
		},
		{ /* 底部分页栏 */
			xtype: 'panel',
			reference: 'bottom',
			dock: 'bottom',
			padding: '7 5 8 10',
			frame: true,
			scrollable: true,
			layout: 'vbox',
			defaults: {
				xtype: 'container',
				layout: 'hbox',
				scrollable: true,
				width: '100%',
				border: true
			},

			items: [
				{ //第一行 container
					defaults: {
						//margin: '5 5 5 0'
					},
					items: [
						{ //挂起按钮
							xtype: 'button',
							margin: '7 5 0 0',
							text: '查看增长日志',
							iconCls: 'x-fa fa-search',
							handler: 'onBtnBuyPointLogClick',
							//disabled: true,
							actiontype: 'suspend' //额外的属性传入handler方法
						}, { //删除按钮
							xtype: 'buttonred',
							margin: '7 5 0 0',
							text: '手动关闭买点',
							iconCls: 'x-fa fa-ban',
							handler: 'onBtnCloseClick',
							actiontype: 'close' //额外的属性传入handler方法
						}, {
							xtype: 'displayfield',
							margin: '4 5 0 0',
							align: 'right',
							value: '|',
							disabled: true
						}, { //现价计算买入点
							xtype: 'buttonyellow',
							margin: '7 5 0 0',
							text: '现价计算买入点',
							iconCls: 'x-fa fa-area-chart',
							handler: 'realtimeBuyinPointAnalyze'
						}, { //查看K线图
							xtype: 'buttonpurple',
							margin: '7 5 0 0',
							text: 'K线图(普通)',
							iconCls: 'x-fa fa-bar-chart',
							handler: 'onBtnKlineChartClick',
							klinetype: 'normal'
						}, { //查看标准K线图
							xtype: 'buttonpurple',
							margin: '7 5 0 0',
							text: 'K线图(标准化)',
							iconCls: 'x-fa fa-bar-chart',
							handler: 'onBtnKlineChartClick',
							klinetype: 'standard'
						},
						{ //底部分页栏
							xtype: 'pagingtoolbar',
							reference: 'bottompagingtoolbar',
							bind: { store: '{buyinPointStore}' },
							displayInfo: true,
							displayMsg: '显示{0}-{1}条, 共{2}条',
							emptyMsg: "无数据显示",
							plugins: [Ext.create('appfe.ux.ComboPageSize', {})],//添加每页条数的选择框
							// items: [ //工具条添加按钮
							// 	{
							// 		xtype: 'buttonred',
							// 		text: '<span style="color:#ffffff;">手动关闭买点</span>',
							// 		iconCls: 'x-fa fa-ban white-awesome-icon'
							// 	}
							// ],
							//layout: 'hbox', // The items are arranged horizontally
							listeners: {
								beforechange: 'pageBarBeforeChange',
								change: function (thisEmt, pageInfo, eopts) {
									if (pageInfo != undefined && pageInfo.currentPage > pageInfo.pageCount) {
										this.moveFirst();
									}
								}
							}
						}
					]
				}
			]
		}
	],
	listeners: {
		render: 'onRender',
		boxready: 'onBoxReady',
		popupLogWin: 'popupLogWin',
		realtimeBuyinPointAnalyze: 'realtimeBuyinPointAnalyze'
	}
});
